package com.ruoyi.shop.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.annotation.InnerAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.shop.domain.CheShop;
import com.ruoyi.shop.service.ICheShopService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商户管理Controller
 * 
 * @author ruoyi
 * @date 2024-06-05
 */
@RestController
@RequestMapping("/shop")
@CrossOrigin
public class CheShopController extends BaseController
{
    @Autowired
    private ICheShopService cheShopService;

    /**
     * 查询商户管理列表
     */
//    @RequiresPermissions("shop:shop:list")
    @GetMapping("/list")
    public TableDataInfo list(CheShop cheShop)
    {
        startPage();
        List<CheShop> list = cheShopService.selectCheShopList(cheShop);

        return getDataTable(list);
    }

    /**
     * 导出商户管理列表
     */
    @RequiresPermissions("shop:shop:export")
    @Log(title = "商户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CheShop cheShop)
    {
        List<CheShop> list = cheShopService.selectCheShopList(cheShop);
        ExcelUtil<CheShop> util = new ExcelUtil<CheShop>(CheShop.class);
        util.exportExcel(response, list, "商户管理数据");
    }

    /**
     * 获取商户管理详细信息
     */
//    @InnerAuth
//    @RequiresPermissions("shop:shop:query")
    @GetMapping(value = "/{id}")

    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cheShopService.selectCheShopById(id));
    }

    /**
     * 新增商户管理
     */
    @RequiresPermissions("shop:shop:add")
    @Log(title = "商户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CheShop cheShop)
    {
        return toAjax(cheShopService.insertCheShop(cheShop));
    }

    /**
     * 修改商户管理
     */
    @RequiresPermissions("shop:shop:edit")
    @Log(title = "商户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CheShop cheShop)
    {
        return toAjax(cheShopService.updateCheShop(cheShop));
    }

    /**
     * 删除商户管理
     */
    @RequiresPermissions("shop:shop:remove")
    @Log(title = "商户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cheShopService.deleteCheShopByIds(ids));
    }
}
